$(function () {
    var paylist_datagrid = $("#paylist_datagrid");
    var paylist_form = $("#paylist_form");
    var paylist_dialog=$("#paylist_dialog");
    

    var cmdObj = {
        //工具栏的刷新
        reload: function () {
            paylist_datagrid.datagrid("reload");
        },

        //查看案件详情
        edit: function () {
            //判断是否选中数据
            var row = paylist_datagrid.datagrid("getSelected");
            console.log(row);
            /*如果没选中数据*/
            if (!row) {
                $.messager.alert('温馨提示', "请选择要查看的数据");
                return;
            }
           //添加与编辑时将数据清空
            paylist_form.form("clear");

            if (row.client) {
                row["client.name"] = row.client.name;
            }
            //数据回显: 同名原则
            paylist_form.form("load", row);
            //1.弹框
            paylist_dialog.dialog("open");
            //设置标题
            paylist_dialog.dialog("setTitle", "案件详情");
        },

        //确认赔付
        ok: function () {
            //判断是否选中数据
            var row = paylist_datagrid.datagrid("getSelected");
           /* console.log(row);*/

            /*  alert(1);
              row.status=1;*/

            if (!row) {
                $.messager.alert('温馨提示', "请选择要编辑的数据");
                return;
            }
            $.messager.confirm('确认', '您确认赔付给客户吗？', function (r) {
                if (r) {
                    $.get("/accident/changeStatus3", {id: row.id,status:row.status}, function (data) {
                        if (data.success) {
                            //刷新列表数据
                            paylist_datagrid.datagrid("reload");
                        } else {
                            $.messager.alert('温馨提示', data.msg);
                        }
                    })
                }
            });
        },

    }

    //调用
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    });

    paylist_datagrid.datagrid({
        url: "/accident/list3",
        fit: true,
        fitColumns: true,
        striped: true,
        singleSelect: true,
        pagination: true,
        rownumbers: true,
        columns: [[
            {field: 'id', checkbox: true},
            {
                field: 'status', title: '当前状态', width: 80, formatter: function (value, row, index) {
                    if(value==0){
                        return "<font color='#a52a2a'>待验证</font>";
                    }
                    else if (value == 1) {
                        return "<font color='#00008b'>验证完,待填理赔</font>";
                    } else if (value == 2) {
                        return "<font color='#00ced1'>废弃</font>";
                    } else if (value == 3) {
                        return "<font color='#6495ed'>待审核</font>";
                    } else if (value == 4) {
                        return "<font color='#daa520'>被拒审核</font>";
                    } else if (value == 5) {
                        return "<font color='#ff6347'>审核完,待付款给保人</font>";
                    } else if (value == 6) {
                        return "<font color='red'>已赔付</font>";
                    }
                    return false;
                }
            },
            {
                field: "client", title: "报案人姓名", width: 100,
                formatter: function (value, row, index) {
                    if (value) {
                        return value.name;
                    } else {
                        return "";
                    }
                }
            },
            {
                field: "guaranteeBill", title: "保险单号", width: 100, formatter: function (value, row, index) {
                    if(value==null){
                        return;
                    }
                    return value.number;
                }
            },
            {
                field: "tel", title: "联系方式", width: 100, formatter: function (value, row, index) {
                    if (row.client) {
                        return row.client.tel;
                    } else {
                        return "";
                    }
                }
            },
            {field: 'oTime', title: '报案时间', width: 80},
            {field: 'duty', title: '事故责任', width: 80},
            {
                field: "inputUser", title: "录入人", width: 100, formatter: function (value, row, index) {
                    if (value) {
                        return value.username;
                    } else {
                        return "";
                    }
                }
            },
            {field: 'remark', title: '备注', width: 80}
        ]],
        toolbar: '#tb'
    });

    paylist_dialog.dialog({
        width: 380,
        height: 380,
        buttons: "#bb",
        closed: true,
        modal: true,
        minimizable: true,
        maximizable: true,
        iconCls: "icon-edit"
    })

});



